package com.sy.service.impl;

import com.sy.dto.CollectDto;
import com.sy.mapper.CollectMapper;
import com.sy.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @author easonsy
 * @Description
 * @createTime 2022/06/24 14:28:00
 */
@Service
public class CollectServiceImpl implements CollectService {
    @Autowired
    private CollectMapper collectMapper;

    @Override
    public List<CollectDto> getAllCollects(Integer memberId) {
        return collectMapper.showCollectSubject(memberId);
    }

    @Override
    public boolean addCollects(Integer memberId, Integer subjectId) {
        if(Objects.nonNull(collectMapper.isExistCollect(memberId,subjectId))){
            return false;
        }
        return collectMapper.addCollect(memberId,subjectId);
    }

    @Override
    public boolean delCollects(Integer memberId, Integer subjectId) {
        if(Objects.nonNull(collectMapper.isExistCollect(memberId,subjectId))){
            return collectMapper.delCollect(memberId,subjectId);
        }
        return false;
    }
}
